package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.pojo.AgentType;
import cn.cs.service.AgentTypeService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping(value = "/agentType")
public class AgentTypeController {

    @Resource
    private AgentTypeService agentTypeService;

    /**
     * 分页查询 经销商分类
     *
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception TODO 添加搜索
     */
    @RequestMapping(value = "/csPlatform/getAgentTypeByPage")
    public Dto getAgentTypeByPage(Integer pageNumber, Integer pageSize) throws Exception {
        Map<String, Object> param = new HashMap<>();
        return DtoUtil.returnSuccess("获取成功", agentTypeService.queryAgentTypePageByMap(param, pageNumber, pageSize));
    }

    /**
     * 查询所有经销商分类
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/getAgentTypeAll")
    public Dto getAgentTypeAll() throws Exception {
        Map<String, Object> param = new HashMap<>();
        return DtoUtil.returnSuccess("获取成功", agentTypeService.getAgentTypeListByMap(param));
    }

    /**
     * 编辑 经销商分类
     * @param agentType
     * @return
     */
    @RequestMapping(value = "/csPlatform/updateAgentType")
    public Dto updateAgentType(@RequestBody AgentType agentType) {
        try {
            String msg = "修改成功";
            agentTypeService.modifyAgentType(agentType);
            return DtoUtil.returnSuccess(msg);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("操作失败，请重试", "001");
        }
    }



}
